package it.aekidna.cleverplatypus.workflow.template
{
	import flash.events.Event;
	
	import it.aekidna.cleverplatypus.gui.containers.commonpopup.GetYesNoAnswerPopUpDialog;
	import it.aekidna.cleverplatypus.mediator.CommandEvent;
	import it.aekidna.cleverplatypus.workflow.AbstractWorkflowTask;
	
	import mx.events.CloseEvent;
	import mx.rpc.events.ResultEvent;

	public class AskYesNoTask extends AbstractWorkflowTask
	{
		public var prompt : String = "REPLACE_ME";
		public var dialog : GetYesNoAnswerPopUpDialog;
		public var hotSpotName : String;
		public var preferredDialogSide : String = null;
		[Bindable]
		public var model : Object;
		
		public function AskYesNoTask()
		{
			super();
		}
		
		override public function begin() : void
		{
			dialog = new GetYesNoAnswerPopUpDialog();
			dialog.closeOnDeactivate = true;
			dialog.prompt = prompt;
			dialog.addEventListener( ResultEvent.RESULT, onYes );
			dialog.addEventListener( Event.CANCEL, onNo );
			dialog.addEventListener( CloseEvent.CLOSE, onNo );
			dialog.hotSpotName = hotSpotName;
			dialog.preferredSide = preferredDialogSide;
			CommandEvent.createWithNamedParams( "SHOW_CONTEXTUAL_POP_UP_PANEL", { panel : dialog } ).dispatch();
		}
		
		private function onYes( inEvent : ResultEvent ) : void
		{
			complete();
		}
		
		private function onNo( inEvent : Event ) : void
		{
			fail( "User aborted operation" );
		}
		
		
		
	}
}